package com.pets.web.controller.api;

import com.pets.common.core.domain.R;
import com.pets.web.dto.WxConfigDto;
import com.pets.web.service.IPetsUserService;
import com.pets.web.vo.ApiWxConfigRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.List;

@Api(tags = "用户相关接口")
@Validated
@RestController
@RequestMapping("/api/user")
public class ApiPetUserController {

    @Autowired
    private IPetsUserService petsUserService;

    @ApiOperation("获取openID")
    @GetMapping("/getOpenId")
    public R<String> getOpenId(@ApiParam("微信授权码") @NotBlank(message = "code不能为空") String code){
        String openId = petsUserService.getOpenId(code);
        return R.ok(openId);
    }

    @ApiOperation("获取WxConfig")
    @PostMapping("/getWxConfig")
    public R<WxConfigDto> getWxConfig(@Validated @RequestBody ApiWxConfigRequest request){
        WxConfigDto dto = petsUserService.getWxConfig(request);
        return R.ok(dto);
    }

}
